import {Button, Input, Modal, Upload, Divider, Image, message} from 'antd';
import React, {useState, useRef, useEffect} from 'react';
import {PageContainer} from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';
import {purchaseList} from './service';
import defaultSetting from '@/../config/defaultSettings';
import Access from '@/components/Access/Access';

import "./index.css";
const TableList = (props) => {
  const actionRef = useRef();
  const [count, setCount] = useState();
  useEffect(() => {

  }, []);

  const simpleColumns = [
    {
      title: '产成品',
      dataIndex: 'searchValue',
      hideInTable:true
    },
    {
      title: '入库时间',
      dataIndex: 'createTime',
      hideInSearch: true,
    },
    {
      title: '入库人',
      dataIndex: 'operator',
      hideInSearch: true,
    },
    {
      title: '状态',
      dataIndex: 'status',
      hideInSearch: true,
      valueEnum: {
        1: {
          text: '审批中',
          status: 'Error',
        },
        9: {
          text: '已入库',
          status: 'Success',
        },
        99: {
          text: '已驳回',
          status: 'Processing',
        },
      },
    },
  ];

  const orderDetailColumns = [
    {
      title: '产品',
      dataIndex: 'title',
      hideInSearch: true,
    },
    {
      title: '条码',
      dataIndex: 'barCode',
      hideInSearch: true,
    },
    {
      title: '入库数量',
      dataIndex: 'value',
      hideInSearch: true,
    },
    {
      title: '库存数量',
      dataIndex: 'sysStock',
      hideInSearch: true,
    },
  ];
  const detailRender = (e)=>{
    return <>
      <ProTable
        rowKey={r=>r.id}
        scroll={{x: 1400}}
        bordered
        dataSource={e.details}
        search={false}
        toolBarRender={false}
        pagination={false}
        columns={orderDetailColumns}
      />
    </>
  };
  return (
    <PageContainer>
      <ProTable
        headerTitle="入库列表"
        actionRef={actionRef}
        rowKey="id"
        search={{
          labelWidth: 120,
        }}
        scroll={{x: 1400}}
        bordered
        request={(params, sorter, filter) => purchaseList({...params, sorter, filter})}
        postData={(payload) => {
          const {list, total} = payload;
          setCount(total);
          return list || [];
        }}
        toolBarRender={() => [

        ]}
        columns={simpleColumns}
        pagination={{
          defaultPageSize: 30,
          showSizeChanger: false,
          showTitle: false,
          total: count,
          showTotal: (total) => `共${total}条`,
        }}
        expandedRowRender={detailRender}
      />
    </PageContainer>
  );
};

export default TableList;
